package com.itheima.reggie.common;

/**
 * 基于TheadLocal封装工具类,用于保存和获取当前登录用户的id
 */

public class BaseContext {

    private static ThreadLocal<Long> threadLocal=new ThreadLocal<>();


    //设置值
    //哪个线程执行此方法，就向当前线程绑定id
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    //获取值
    //哪个线程执行此方法，就像从当前线程获取id
    public static Long getCurrentId(){
        return threadLocal.get();
    }

    //移除
    public static void removeId(){
        threadLocal.remove();
    }

}
